<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>按照 RFC 3986 对 URL 进行编码</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.rawurlencode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">rawurlencode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">rawurlencode</span> &mdash; <span class="dc-title">按照 RFC 3986 对 URL 进行编码</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.rawurlencode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>rawurlencode</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   根据 <a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a> 编码指定的字符。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.rawurlencode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       要编码的 URL。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.rawurlencode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回字符串，此字符串中除了
   <em>-_.</em> 
   之外的所有非字母数字字符都将被替换成百分号（<em>%</em>）后跟两位十六进制数。这是在
   <a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a> 中描述的编码，是为了保护原义字符以免其被解释为特殊的 
   URL 定界符，同时保护 URL 
   格式以免其被传输媒体（像一些邮件系统）使用字符转换时弄乱。
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     在 PHP 5.3.0 之前，rawurlencode 根据 <a href="http://www.faqs.org/rfcs/rfc1738" class="link external">&raquo;&nbsp;RFC 1738</a> 来编码波浪线（<em>~</em>）。
    </p>
   </p></blockquote>
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.rawurlencode-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.4</td>
       <td>
        因为 <span class="function"><strong>rawurlencode()</strong></span> 使用了  EBCDIC，所以波浪线字符不会再被编码。
       </td>
      </tr>

      <tr>
       <td>5.3.0</td>
       <td>
        现在符合了<a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.rawurlencode-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4894">
    <p><strong>Example #1 在 FTP URL 里包含一个密码</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="ftp://user:'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">rawurlencode</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo&nbsp;@+%/'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'@ftp.example.com/x.txt"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;a href=&quot;ftp://user:foo%20%40%2B%25%2F@ftp.example.com/x.txt&quot;&gt;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   或者，如果你想通过 URL 的 PATH_INFO 构成部分去传递信息：
  </p>
  <p class="para">
   <div class="example" id="example-4895">
    <p><strong>Example #2 <span class="function"><strong>rawurlencode()</strong></span> 示例 2</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="http://example.com/department_list_script/'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rawurlencode</span><span style="color: #007700">(</span><span style="color: #DD0000">'sales&nbsp;and&nbsp;marketing/Miami'</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;a href=&quot;http://example.com/department_list_script/sales%20and%20marketing%2FMiami&quot;&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.rawurlencode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="rawurldecode.html" class="function" rel="rdfs-seeAlso">rawurldecode()</a> - 对已编码的 URL 字符串进行解码</span></li>
    <li class="member"><span class="function"><a href="urldecode.html" class="function" rel="rdfs-seeAlso">urldecode()</a> - 解码已编码的 URL 字符串</span></li>
    <li class="member"><span class="function"><a href="urlencode.html" class="function" rel="rdfs-seeAlso">urlencode()</a> - 编码 URL 字符串</span></li>
    <li class="member"><a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>